package com.zhouwr.common.metadata;

import com.alibaba.fastjson.JSON;
import com.zhouwr.common.enums.ModelDataType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.StringJoiner;

/**
 * @program: forallcn-iotps
 * @description: 字符串类型
 * @author: zhouwr
 * @create: 2020-11-19 15:15
 * @version：1.0
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class StringData extends Metadata<String> {
    private Integer minLength;
    private Integer maxLength;
    private Integer strLength;
    private String defaultValue = "";
    ModelDataType type =  ModelDataType.STRING;


    public static StringData form(String metadata){
        return JSON.toJavaObject(JSON.parseObject(metadata), StringData.class);
    }

    @Override
    public String getDefaultValue() {
        return this.defaultValue;
    }


    @Override
    public String toString() {
        return new StringJoiner(", ", StringData.class.getSimpleName() + "[", "]")
                .add("minLength=" + minLength)
                .add("maxLength=" + maxLength)
                .add("strLength=" + strLength)
                .toString();
    }
}
